#!/bin/bash
set -e

export TZ=UTC
export HOME=/remote/iosg/home/bot-coin
source ~/miniconda3/etc/profile.d/conda.sh
conda activate coin2_env

cd ~/jenkins/workspace/coin2_fastfeed/coin

NUM_PARALLEL="512"
parallel -j "${NUM_PARALLEL}" --joblog index-gen.log <<EOF
{% for trading_date in settings.keys() -%}
{% for machine in settings[trading_date].keys() -%}
{% for mea in settings[trading_date][machine].keys() -%}
{% for recipe in settings[trading_date][machine][mea].keys() -%}
{% for group in settings[trading_date][machine][mea][recipe].keys() -%}
srun --job-name={{job_id}} -N1 -n1 -l --mem-per-cpu=1G --exclusive catchsegv bazel-bin/cc/appcoin2/support/feed/index_generator --driver={{settings[trading_date][machine][mea][recipe][group]}} --date={{trading_date}} --out-machine={{machine}}
{% endfor -%}
{% endfor -%}
{% endfor -%}
{% endfor -%}
{% endfor -%}
EOF

cd /remote/iosg/home/bot-hft/jenkins/workspace/coin2_feed_stats/coin/python
python -m coin.tool.mailer --name="index-generate" --mailfrom="coin-sim@joomo.io" --mailto="{{summary_mailto}}" --subject="{{mail_subject}}" <<EOF
Slurm job ID:     ${SLURM_JOB_ID}
Output directory: ${OUTDIR}
User tag:         None

---
$(scontrol show job ${SLURM_JOB_ID})
EOF
